package com.spa.modules.spa.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.spa.common.api.vo.Result;
import com.spa.common.aspect.annotation.AutoLog;
import com.spa.modules.spa.entity.SpaMenu;
import com.spa.modules.spa.service.SpaMenuService;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 描述: 菜单
 * author: zw
 * date: 2023-01-14 14:23:46
 */
@Api(tags="菜单")
@RestController
@RequestMapping(value="/spa/spaMenu")
public class SpaMenuController {

    @Autowired
	private SpaMenuService spaMenuService;

    /**
     * 分页列表查询
     * 
     * @param spaMenu
     * @param pageNo
     * @param pageSize
     * @return
     */
    @AutoLog(value = "菜单-列表")
    @ApiOperation(value="菜单-列表", notes="菜单-列表")
    @SaCheckPermission("spa:spaMenu:menuTrue")  
    @GetMapping(value = "/menuTrueAll")
    public Result<?> getMenuTrueAll() {
        return spaMenuService.getMenuTrueAll();
    }
    
	/**
	 * 分页列表查询
	 * 
	 * @param spaMenu
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@AutoLog(value = "菜单-列表")
	@ApiOperation(value="菜单-列表", notes="菜单-列表")
	@SaCheckPermission("spa:spaMenu:menuTrue")  
	@GetMapping(value = "/menuTrue")
	public Result<?> getMenuTrue() {
		return spaMenuService.getMenuTrue();
	}
	
	/**
     * 根据登录用户角色获取菜单
     * 
     * @param spaMenu
     * @param pageNo
     * @param pageSize
     * @return
     */
    @AutoLog(value = "根据登录用户角色获取菜单")
    @ApiOperation(value="获取菜单", notes="根据登录用户角色获取菜单")
    @GetMapping(value = "/menuListByLoginId")
    public Result<?> getMenuListByLoginId() {
        return spaMenuService.getMenuListByLoginId();
    }
	
	/**
     * 根据登录用户角色获取菜单
     * 
     * @param spaMenu
     * @param pageNo
     * @param pageSize
     * @return
     */
    @AutoLog(value = "根据登录用户角色获取菜单")
    @ApiOperation(value="获取菜单", notes="根据登录用户角色获取菜单")
    @GetMapping(value = "/getMenuList")
    public Result<?> getMenuList() {
        return spaMenuService.getMenuListByRole();
    }
     
    /**
	 * 添加
	 *
	 * @param spaMenu
	 * @return
	 */
	@AutoLog(value = "菜单-添加")
	@ApiOperation(value="菜单-添加", notes="菜单-添加")
	//@SaCheckPermission("spa:spaMenu:add")  
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody SpaMenu spaMenu) {
		return spaMenuService.insert(spaMenu);
	}
	
	/**
	 * 编辑
	 *
	 * @param spaMenu
	 * @return
	 */
	@AutoLog(value = "菜单-编辑")
	@ApiOperation(value="菜单-编辑", notes="菜单-编辑")
	//@SaCheckPermission("spa:spaMenu:edit")  
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody SpaMenu spaMenu) {
		return spaMenuService.saveById(spaMenu);
	}
	
	/**
	 * 通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "菜单-通过id删除")
	@ApiOperation(value="菜单-通过id删除", notes="菜单-通过id删除")
	//@SaCheckPermission("spa:spaMenu:delete") 
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) Long id) {
		return spaMenuService.deleteById(id);
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "菜单-通过id查询")
	@ApiOperation(value="菜单-通过id查询", notes="菜单-通过id查询")
	//@SaCheckPermission("spa:spaMenu:queryById")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) Long id) {
		return spaMenuService.selectById(id);
	}
}
